<template>
  <div>
           <div class="title">
       <p class="iconfont icon-bg-left" @click="handleBack"></p>
       <p>光与影</p>
       <p class="iconfont icon-shenglvehao"></p>
     </div>
  <Item :data='data'></Item>

  </div>
</template>

<script>
import Item from './components/Item.vue'
export default {
   data(){
       return{
           data:[]
       }
   },
   components:{
       Item
   },
   methods:{
       handleBack(){
           this.$router.back()
       },
        getHotRes(url) {
      this.$http(url).then((res) => {
           res.data.res.forEach(item => {
            item.count=this.getArrayStr(item.rating)
        });
        this.data=res.data.res
      });
    },
    getNewest(url) {
      this.$http(url).then((res) => {
           res.data.res.forEach(item => {
            item.count=this.getArrayStr(item.raiting)
        });
        this.data=res.data.res
      });
   
    },
    getDjRes(url) {
      this.$http(url).then((res) => {
       res.data.res.forEach(item => {
            item.count=this.getArrayStr(item.rating)
        });
        this.data=res.data.res
      });
    },
           getArrayStr(sum){
         var arr=[]
         for(var i=0;i<5;i++){
            
             if(sum>2){
               arr.push(2)
             }else if(sum>0){
               arr.push(Math.round(sum*10)/10)
             }else{
               arr.push(0)
             }
              sum=sum-2
         }
         return arr
       },
   },
  mounted(){
         var { url } = this.$route.query;
         console.log(url);
    var arr = [
      "http://47.108.197.28:4000/api/movie/top250",
      "http://47.108.197.28:4000/api/movie/inTheaters",
      "http://47.108.197.28:4000/api/movie/comingSoon",
    ];
    if (url == arr[0]) {
      this.getHotRes(url);
    } else if (url == arr[1]) {
      this.getNewest(url);
    } else if (url == arr[2]) {
      this.getDjRes(url);
    }
  }
}
</script>

<style scoped>
.title{
  height: 70px;
  width: 10rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgb(99, 131, 219);
}
.title p{
  font-size: 35px;
  color: white;
}
</style>